package com.longrise.android.byjk.plugins.dealsituation.course.video2.education.insurance.videocontroller;

import android.app.Activity;
import android.content.Context;
import android.view.Window;
import android.view.animation.AlphaAnimation;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;

import com.longrise.android.byjk.plugins.dealsituation.course.video2.media.IjkVideoView;

import java.lang.ref.WeakReference;

/**
 * Created by godliness on 2017/9/4.
 */

public abstract class BaseController {

    private WeakReference<IjkVideoView> mVideoView;

    public void addVideoController(IjkVideoView videoView) {
        mVideoView = new WeakReference<>(videoView);
    }

    protected final boolean notNull() {
        if (mVideoView == null) {
            return false;
        }
        return mVideoView.get() != null;
    }

    protected final Context getContext() {
        if (notNull()) {
            return mVideoView.get().getContext();
        }
        //AppCxt.get()
        return null;
    }

    protected final Window getWindow() {
        Context cxt = getContext();
        if (cxt != null && cxt instanceof Activity) {
            Activity cAct = (Activity) cxt;
            return cAct.getWindow();
        }
        return null;
    }

    protected final IjkVideoView get() {
        return mVideoView.get();
    }

    protected AlphaAnimation alphaTo(int duration, int... to) {
        AlphaAnimation alphaShow = new AlphaAnimation(to[0], to[1]);
        alphaShow.setDuration(duration);
        return alphaShow;
    }

    protected TranslateAnimation alphaTran(int duration, float... to) {
        TranslateAnimation transTo = new TranslateAnimation(1.0f, 1.0f, to[0], to[1]);
        transTo.setDuration(duration);
        return transTo;
    }

    protected AnimationSet amsSetTo(int duration, int... to){
        AnimationSet animationSet = new AnimationSet(true);
        animationSet.addAnimation(alphaTo(duration, to[0], to[1]));
        animationSet.addAnimation(alphaTran(duration));
        return animationSet;
    }

}
